<!DOCTYPE html>
<title>Tests that added cue object wrappers live across garbage collections.</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<video></video>
<script>
async_test(function(t) {
    var cueIndex = 0;
    var cueLimit = 10;
    var video = document.querySelector("video");
    video.src = "../content/test.ogv";

    video.textTracks.custom = "trackList";
    assert_true(video.textTracks.hasOwnProperty("custom"));

    // Add a text track to the video element.
    var track = video.addTextTrack("captions", "regular captions track", "en");
    track.custom = "track";
    assert_true(track.hasOwnProperty("custom"));

    // Add cues with own native property to the track with enter event listener.
    for (var i = 0; i < cueLimit; i++) {
        var cue = new VTTCue(i / 4, i / 2 + 1, "Label" + i);
        cue.custom = "cue";

        cue.onenter = t.step_func(function(event) {
            var currentCue = event.target;
            assert_true(currentCue.hasOwnProperty("custom"));
            if (++cueIndex == cueLimit)
                t.done();
        });

        track.addCue(cue);
    }

    for (var i = 0; i < cueLimit; i++) {
        var cue = track.cues[i];
        assert_true(cue.hasOwnProperty("custom"));
    }

    // Trigger a garbage collection.
    track = null;
    gc();

    assert_true(video.textTracks.hasOwnProperty("custom"));

    track = video.textTracks[0];
    assert_true(track.hasOwnProperty("custom"));

    // Play the video and test cue wrappers.
    video.play();
    track.mode = "showing";
});
</script>